package com.heima.exception;

import com.heima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
//全局异常处理器
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler
    public Result ex(Exception e){
    String msg = e.getMessage();
    log.error("出问题了",msg);
    e.printStackTrace();
    if(msg.contains("Duplicate entry")){
        return Result.error("数据重复");
    }else {
        return Result.error("未知错误");
    }
}
}
